home *** CD-ROM | disk | FTP | other *** search
- KNOW-HOW.GRAF
- Screen diagrams output.
- (C) Stepan S. Vartanov, 1993
-
- AXE.H and AXE.CPP.
- Abstract axe, horizontal or vertical:
-
- #ifndef __AXE_H_
- #define __AXE_H_
-
- #include "graphpp.h"
- #include <string.h>
-
- struct Axe
- {
- int len_scr; // Pixels, axe len
- int* ticks; // Ticks
- int* sub_ticks; // Sub-ticks
- char** labels; // Ticks labels
- int ticks_no; // Number of ticks
- int sub_ticks_no;
- Axe(int l, double start = 0, double end = 0,
- int tick_no = 5, int* t = NULL,
- int s_tick_no = 0, int* s = NULL,
- char** lab = NULL);
- ~Axe();
-
- virtual loc get_label_pos(loc, int )
- { return loc(0, 0); }
- Draw axe
- virtual void show_axe(loc, int) {}
- Draw axe and labels
- void draw_axe(loc left_topt, int, int);
- virtual void show_labels(loc) {}
- Auto calc labels positions
- int calc_labels(double start, double end,
- int number_of_ticks = 5, int number_of_sub_ticks = 0);
- };
-
- #endif __AXE_H_
-
- H_V_AXES.H.
- Horizontal or vertical axe.
-
- #ifndef __HORIZ_VERT_AXES_H_
- #define __HORIZ_VERT_AXES_H_
-
- #include "axe.h"
-
- enum axes_dir { HORIZ_AXE, VERT_AXE };
- Normal axe have labels on the left-down side
- enum axes_type { NORMAL_AXE, REVERSE_AXE };
-
- class HV_Axes : public Axe
- {
- protected:
- int type;
- int dir;
- public:
- HV_Axes(int l, double start = 0, double end = 0,
- int tick_no = 0, int* t = NULL,
- int s_tick_no = 0, int* s = NULL,
- char** lab = NULL);
-
- virtual void show_labels(loc label_position);
- void set_type(int label_type, int label_dir);
- virtual loc get_label_pos(loc, int );
-
- virtual void show_axes(loc left_top, int);
- };
-
- #endif __HORIZ_VERT_AXES_H_
-
- Example:
-
- void main()
- {
- int gdriver = DETECT, gmode;
- initgraph(&gdriver, &gmode, "");
-
- HV_Axes a(300, -20, 80);
- a.set_type(NORMAL_AXE, HORIZ_AXE);
-
- a.draw_axe(loc(40, 320), LIGHTBLUE, YELLOW);
-
- a.set_type(REVERSE_AXE, HORIZ_AXE);
- a.draw_axe(loc(40, 20), LIGHTBLUE, YELLOW);
-
- a.set_type(NORMAL_AXE, VERT_AXE);
- a.draw_axe(loc(40, 20), LIGHTBLUE, YELLOW);
-
- a.set_type(REVERSE_AXE, VERT_AXE);
- a.draw_axe(loc(340, 20), LIGHTBLUE, YELLOW);
-
- HV_Axes a2(200, -25, 80);
- a2.set_type(NORMAL_AXE, HORIZ_AXE);
- a2.draw_axe(loc(420, 20), LIGHTBLUE, YELLOW);
-
- HV_Axes a3(200, -122, 83);
- a3.set_type(NORMAL_AXE, HORIZ_AXE, VERT_DIR);
- a3.draw_axe(loc(420, 60), LIGHTBLUE, YELLOW);
-
- HV_Axes a4(200, -5635, -3558);
- a4.set_type(NORMAL_AXE, HORIZ_AXE, VERT_DIR);
- a4.draw_axe(loc(420, 140), LIGHTBLUE, YELLOW);
-
- HV_Axes a5(200, 0, 1180);
- a5.set_type(NORMAL_AXE, HORIZ_AXE, VERT_DIR);
- a5.draw_axe(loc(420, 240), LIGHTBLUE, YELLOW);
-
- int t[] = { 0, 5000, 10000 };
- int s[] = { 1000, 2000, 3000, 4000, 5000, 6000, 7000, 8000, 9000 };
-
- char* lab[] = { "First", "Second", "Third" };
-
- HV_Axes a1(200, 0, 0, 3, t, 9, s, lab);
-
- a1.set_type(NORMAL_AXE, HORIZ_AXE);
- a1.draw_axe(loc(60, 300), LIGHTGREEN, LIGHTRED);
-
- a1.set_type(REVERSE_AXE, HORIZ_AXE);
- a1.draw_axe(loc(60, 270), LIGHTGREEN, LIGHTRED);
-
- a1.set_type(NORMAL_AXE, VERT_AXE);
- a1.draw_axe(loc(100, 40), LIGHTGREEN, LIGHTRED);
-
- a1.set_type(REVERSE_AXE, VERT_AXE);
- a1.draw_axe(loc(120, 40), LIGHTGREEN, LIGHTRED);
-
- closegraph();
- }
-
-
- File Axes2.
- 2 - 3 - 4 axes.
-
- #ifndef __AXES2_H_
- #define __AXES2_H_
-
- #include "h_v_axes.h"
-
- enum { HORIZ1, VERT1, HORIZ2, VERT2 };
-
- class Axes2
- {
- protected:
- HV_Axes* horiz_axe;
- HV_Axes* vert_axe;
- HV_Axes* horiz_axe_2;
- HV_Axes* vert_axe_2;
- public:
- Axes2();
- ~Axes2()
- { delete horiz_axe; delete vert_axe;
- delete horiz_axe_2; delete vert_axe_2; }
- Cross on 0, 0
- void cross(rect coord, loc zero);
- void set_axe(int which, int l, double start = 0,
- double end = 0,
- int tick_no = 0, int* t = NULL,
- int s_tick_no = 0, int* s = NULL,
- char** lab = NULL, int text_direction);
-
- void show(loc lt, int ax_col, int lab_col);
- };
-
- #endif __AXES2_H_
-
- Example:
-
- void main()
- {
- int gdriver = DETECT, gmode;
- initgraph(&gdriver, &gmode, "");
-
- Axes2* a = new Axes2();
-
- a->set_axe(HORIZ1, 300, -20, 80);
- a->set_axe(HORIZ2, 300, -20, 80);
- a->set_axe(VERT1, 300, -20, 80);
- a->set_axe(VERT2, 300, -20, 80);
-
- a->show(loc(40, 20), LIGHTBLUE, YELLOW);
-
- delete a;
-
- closegraph();
- }
-
-
- File GRAF
- ò-ô curves.
-
- #ifndef __GRAF_H_
- #define __GRAF_H_
-
- #include "marker.h"
-
- enum { NO_GRAF, LINE_GRAF, MARKER_GRAF, COMBINED_GRAF,
- BAR_GRAF, BAR_3D_GRAF, STACKED_BAR_GRAF };
-
- struct Graf
- {
- int marker_type;
- int line_type;
- int attr;
- int bak;
- int size; // Marker size
- int fill; // Fill (for bars)
-
- Graf(int m, int l, int a, int b, int s, int f)
- { marker_type = m; line_type = l; attr = a;
- bak = b; size = s; fill = f; }
- void set_type(int m, int l, int a, int b, int s,
- int f)
- { marker_type = m; line_type = l; attr = a;
- bak = b; size = s; fill = f; }
- void show(int* x, int* y, int numpoints, int x0,
- int y0, int no = 0);
- void set_type(int m_t, int l_t)
- { line_type = l_t; marker_type = m_t; }
- void set_param(int a, int b, int s, int f)
- { attr = a; bak = b; size = s; fill = f; }
- };
-
- #endif __GRAF_H_
-
- Example:
-
- void main()
- {
- int gdriver = DETECT, gmode;
- initgraph(&gdriver, &gmode, "");
-
- int x[] = { -50, -25, 0, 25, 50 };
- int y[] = { -50, 30, -10, 20, 0 };
-
- Graf g(BAR, LINE_GRAF, LIGHTGREEN, RED, 4, SLASH_FILL);
- g.show(x, y, 5, 60, 60);
-
- setviewport(120, 0, 240, 240, 1);
- g.set_type(BAR, MARKER_GRAF, LIGHTGREEN, RED, 4, SLASH_FILL);
- g.show(x, y, 5, 60, 60);
-
- setviewport(240, 0, 360, 240, 1);
- g.set_type(BAR, COMBINED_GRAF, LIGHTGREEN, RED, 4, SLASH_FILL);
- g.show(x, y, 5, 60, 60);
-
- setviewport(360, 0, 480, 240, 1);
- g.set_type(BAR, BAR_GRAF, LIGHTGREEN, RED, 12, SLASH_FILL);
- g.show(x, y, 5, 60, 60);
-
- setviewport(500, 0, 630, 240, 1);
- g.set_type(BAR, BAR_3D_GRAF, LIGHTGREEN, RED, 12, SLASH_FILL);
- g.show(x, y, 5, 60, 60);
-
- closegraph();
- }
-
-
- File GRAFIC.
- Shell for above functions. Also could save - load datasets
- to - from disk for memory economy.
-
- #ifndef __GRAFIC_H_
- #define __GRAFIC_H_
-
- #include "axes2.h"
- #include "graf.h"
-
-
- struct GrafData
- {
- Graf* graf;
- int* data_x; // ò-array
- int* data_y; // ô-array
- int num_points; // Total points number
- char* fileName; // swap file
-
- è«¡ßΓαπ¬Γ«α
- GrafData(char attr_color, char back_color,
- int marker_type, int line_type, int size_of_marker,
- int fill_style, int* data_x, int* data_y,
- int number_of_points, char* fName = "");
- ~GrafData();
- void load();
- void save();
- };
-
- Draw axes and datasets:
-
- class Grafic : public Axes2
- {
- protected:
- int used; // Dataset number (1-15)
- rect coord; // Clip
- rect work_coord; // Work area, excluding labels
- int ax_col; int lab_col; // Colors
- loc zero;
- double zero_x;
- double zero_y;
- double len_x;
- double len_y;
- int grid_style;
- public:
- GrafData* arrays[15];
- Grafic(rect clip_area, int axe_type, int lab,
- int grafics_num = 5, int save = 0);
- ~Grafic();
-
- rect get_work_coord() { return work_coord; }
- loc get_colors() { return loc(ax_col, lab_col); }
- void grid();
- loc get_zero(double xmin, double ymin, double xmax,
- double ymax);
- int bar_width();
- void get_x_array(int ar, int num, double* data);
- void get_y_array(int ar, int num, double* data);
- rect set_work_rect(rect r) { return work_coord = r; }
- void set_rect(rect r) { coord = r; }
- void redraw();
- void show_axes();
- int* get_stacked(int n);
- };
-
- #endif __GRAFIC_H_
-
-
- Example:
-
- void main()
- {
- int gdriver = DETECT, gmode;
- initgraph(&gdriver, &gmode, "");
-
- static int t[] = { 0, 5000, 10000 };
- static int s[] = { 1111, 2222, 3333, 4444, 5555, 6666, 7777, 8888 };
- static char* lab[] = { "First", "Second", "Third" };
-
- bar(0, 0, 639, 479);
- rect rc = rect(5, 5, 639, 479);
- rectangle(rc);
- Grafic a(rc, BLUE, GREEN, 2, 1);
-
- rect r = a.set_work_rect(rect(90, 50, 450, 250));
- // Auto calc ticks and sub_ticks
- a.set_axe(HORIZ1, r.width() - 1, -1.00, 1.00, 5, NULL);
- a.set_axe(HORIZ2, r.width() - 1, 0, 0, 3, t, 8, s, lab);
- // Auto calc ticks and pass array of sub_ticks
- a.set_axe(VERT1, r.height() - 1, -300, 600, 10, NULL, 8, s);
-
- a.set_axe(VERT2, r.height() - 1, 0, 0, 3, t, 8, s, lab);
-
- loc z = a.get_zero(-1.00, -300, 1.00, 600);
-
- a.grid();
- setcolor(BLACK);
- a.show_axes();
-
- z = z - a.get_work_coord().origin;
- static double x_ar[] = { -.80, -.60, -.40, -.20, 0, .20, .40,
- .60, .80 };
- static double y1_ar[] = { -200, -150, -100, -50, 0, 50, 100, 150,
- 200 };
- static double y2_ar[] = { -100, 100, -20, -5, 19, 100, 200, 100,
- 100 };
-
- a.get_x_array(0, 9, x_ar);
- a.get_y_array(0, 9, y1_ar);
- a.get_x_array(1, 9, x_ar);
- a.get_y_array(1, 9, y2_ar);
- a.get_x_array(2, 9, x_ar);
- a.get_y_array(2, 9, y2_ar);
-
- a.arrays[0]->graf->set_type(BAR, STACKED_BAR_GRAF);
- a.arrays[1]->graf->set_type(BAR, STACKED_BAR_GRAF);
- a.arrays[2]->graf->set_type(BAR, STACKED_BAR_GRAF);
-
- int w = a.bar_width();
- a.arrays[0]->graf->set_param(RED, GREEN, w,
- SLASH_FILL);
- a.arrays[1]->graf->set_param(RED, CYAN, w,
- LINE_FILL);
- a.arrays[2]->graf->set_param(RED, RED, w,
- XHATCH_FILL);
-
- setviewport(a.get_work_coord(), 1);
-
- int* array = a.get_stacked(0);
- a.arrays[0]->graf->show(a.arrays[0]->data_x, array, 9,
- z.X, z.Y);
- delete array;
- array = a.get_stacked(1);
- a.arrays[1]->graf->show(a.arrays[1]->data_x, array, 9,
- z.X, z.Y);
- delete array;
- array = a.get_stacked(2);
- a.arrays[2]->graf->show(a.arrays[2]->data_x, array, 9,
- z.X, z.Y);
- delete array;
-
- setfillstyle(SOLID_FILL, WHITE);
- setviewport(0, 0, getmaxx(), getmaxy(), 1);
- bar(0, 0, 639, 479);
-
- Grafic a1(rc, BLUE, GREEN, 2, 1);
-
- r = a1.set_work_rect(rect(100, 100, 300, 300));
-
- a1.set_axe(HORIZ1, r.width() - 1, -1.00, 1.00, 5, NULL, 0, NULL,
- NULL, VERT_DIR);
- a1.set_axe(HORIZ2, r.width() - 1, 0, 0, 3, t, 8, s, lab);
- a1.set_axe(VERT1, r.height() - 1, -300, 300, 10, NULL, 0, NULL);
- a1.set_axe(VERT2, r.height() - 1, 0, 0, 3, t, 8, s, lab);
-
- z = a1.get_zero(-1.00, -300, 1.00, 300);
-
- a1.grid();
- setcolor(BLACK); // FOR CROSS
- a1.show_axes();
-
- z = z - a1.get_work_coord().origin;
-
- a1.get_x_array(0, 9, x_ar);
- a1.get_y_array(0, 9, y1_ar);
- a1.get_x_array(1, 9, x_ar);
- a1.get_y_array(1, 9, y2_ar);
- a1.get_x_array(2, 9, x_ar);
- a1.get_y_array(2, 9, y1_ar);
-
- a1.arrays[0]->graf->set_type(BAR, COMBINED_GRAF);
- a1.arrays[1]->graf->set_type(CIRCLE, BAR_3D_GRAF);
- a1.arrays[2]->graf->set_type(TRIANGLE, BAR_3D_GRAF);
-
- w = a1.bar_width();
- a1.arrays[0]->graf->set_param(RED, GREEN, w,
- SLASH_FILL);
- a1.arrays[1]->graf->set_param(RED, CYAN, w,
- LINE_FILL);
- a1.arrays[2]->graf->set_param(RED, RED, w,
- XHATCH_FILL);
-
- setviewport(a1.get_work_coord(), 1);
-
- a1.arrays[0]->graf->show(a1.arrays[0]->data_x,
- a1.arrays[0]->data_y, 9, z.X, z.Y, 0);
- a1.arrays[1]->graf->show(a1.arrays[1]->data_x,
- a1.arrays[1]->data_y, 9, z.X, z.Y, 1);
- a1.arrays[2]->graf->show(a1.arrays[2]->data_x,
- a1.arrays[2]->data_y, 9, z.X, z.Y, 2);
-
- closegraph();
- }
-
-